let compare a b = 
	if a = b then 0
	else if a > b then 1
	else -1;;
	
let rec find name liste = 
	match liste with
		[] -> failwith "Ce client n'existe pas"
		|(name1,n1)::liste -> match compare (String.lowercase name1) (String.lowercase name) with
								0 -> n1
								|_ -> find name liste;;
						
let rec add (name,n) liste =
	match liste with
		[] -> [(name,n)]
		|(name1,n1)::liste -> match compare (String.lowercase name1) (String.lowercase name) with
								0 -> (name1,n1) :: liste
								|1 -> (name,n) :: (name1,n1) :: liste
								|_ -> (name1,n1) :: add (name,n) liste;;			
			
let rec delete name liste = 
	match liste with
		[] -> liste
		|(name1,n1)::liste -> match compare (String.lowercase name1) (String.lowercase name) with
								0 -> liste
								|_ -> (name1,n1) :: delete name liste;;

let rec update name n liste = 
	match liste with
		[] -> failwith "Ce client n'existe pas"
		|(name1,n1)::liste ->  match compare (String.lowercase name1) (String.lowercase name) with 	
								0 -> (name1,n) :: liste 
								|_ -> (name1,n1) :: update name n liste;;	
							
let rec name old_name new_name liste = 
	delete old_name (add (new_name,(find old_name liste)) liste);;

let rec map f liste = 
	match liste with
		[] -> []
		|a1::liste -> ( f a1 ) :: ( map f liste );;
		
let rec sales liste p = 
	match liste with
		[] -> []
		|(nom,n)::liste -> (nom, n -. ((n *. p)/.100.)) :: ( sales liste p );;

let rec fusion (l1,l2) = 
	match (l1,l2) with
		([],[]) -> []
		|(l1,[]) -> l1
		|([],l2) -> l2
		|((name1,n1)::l1,(name2,n2)::l2) -> 
			match compare (String.lowercase name1) (String.lowercase name2) with
				|0 -> (name1,n1 +. n2) :: fusion (l1,l2)
				|1 -> (name2,n2) :: fusion (((name1,n1)::l1),l2)
				|_ -> (name1,n1) :: fusion (l1,((name2,n2)::l2));;
